package com.sense.kukoo.biz_me.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.sense.feel.common.utils.ToastUtils
import com.sense.kukoo.biz_me.R
import com.sense.kukoo.biz_me.databinding.BizMeActivityManageAccountBinding
import com.sense.kukoo.biz_me.vm.ManageAccountViewModel
import com.sense.kukoo.common.constant.ARouterUrl
import com.sense.kukoo.common.event.LogoutEvent
import com.sense.kukoo.common.mvvm.view.BaseMvvmActivity
import com.sense.kukoo.common.utils.ApplicationContext
import com.sense.kukoo.common.wiget.dialog.MiddleConfigDialog
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

@Route(path = ARouterUrl.ROUTE_ME_MODULE_MANAGE_ACCOUNT_ACTIVITY)
class ManageAccountActivity : BaseMvvmActivity<ManageAccountViewModel, BizMeActivityManageAccountBinding>() {

    override fun getLayoutId(): Int = R.layout.biz_me_activity_manage_account

    override fun getViewModelClass(): Class<ManageAccountViewModel> = ManageAccountViewModel::class.java

    override fun responseVM(action: Int) {}

    override fun initData() {
        mBinding.lifecycleOwner = this
        mBinding.vm = mViewModel
        mBinding.titleView.init(this)
        setSupportActionBar(mBinding.titleView)
        //
        bindAction(mViewModel.action_toShowDialog){
            showDialog()
        }
    }

    override fun initView() {}

    private fun showDialog(){
        val dialog = MiddleConfigDialog(this)
        val mListener = object : MiddleConfigDialog.MiddleConfigListener{
            override fun onLeftClick() {
                dialog.dismiss()
            }

            override fun onRightClick() {
                dialog.dismiss()
                mViewModel.onDeleteAccount()
            }
        }
        dialog
            .setTitleStr(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.settings_delete_account_title))
            .setMsgStr(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.settings_delete_account_content))
            .setBtnLeft(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.settings_cache_left_btn), getResources().getColor(com.sense.kukoo.common.R.color.dialog_btn_text_color_blue_2))
            .setBtnRight(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.library_delete), getResources().getColor(com.sense.kukoo.common.R.color.dialog_btn_text_color_red))
            .setListener(mListener)
            .show()
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onMessageEvent(event: LogoutEvent) {
        finish()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        EventBus.getDefault().register(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }

}